import unittest

import requests

from api import log
from api.api_approve_trust import ApiApproveTrust
from api.api_register_login import ApiRegisterLogin
from api.api_tender import ApiTender
from utils import parser_html


class TestTenderList(unittest.TestCase):
    def setUp(self) -> None:
        self.session = requests.Session()
        # ApiApproveTrust
        self.approve = ApiApproveTrust(self.session)
        # ApiRegisterLogin
        self.reg = ApiRegisterLogin(self.session)
        # ApiTender
        self.tender = ApiTender(self.session)

    def tearDown(self) -> None:
        self.session.close()

    def test01_tender_list(self):
        # 1、获取图片验证码
        self.reg.api_img_code(123)
        # 2、获取短信验证码
        self.reg.api_msg_code('13012341112', 8888)
        # 3、注册
        self.reg.api_register('13012341112', 'test123', 8888, 666666)
        # 4、登录
        self.reg.api_login('13012341112','test123')
        # 5、认证
        self.approve.api_approve('210404196512092409')
        # 6、开户
        resp = self.approve.api_trust()
        # 7、三方开户
        res = parser_html(resp)
        resp = self.session.post(url=res[0], data=res[1])
        print('三方开户结果为:', resp.text)
        log.info('执行接口结果为:{}'.format(resp.text))
        self.assertIn('OK', resp.text)
        log.info('断言成功')
        # 8、获取充值验证码
        self.approve.api_img_code(123)
        # 9、后台充值
        resp = self.approve.api_recharge(8888)
        # 10、三方充值
        res = parser_html(resp)
        resp = self.session.post(url=res[0], data=res[1])
        print('三方充值结果为:', resp.text)
        log.info('执行接口结果为:{}'.format(resp.text))
        self.assertIn('OK', resp.text)
        log.info('断言成功')
        # 11、后台投资
        resp = self.tender.api_tender(100)
        # 12、三方投资
        res = parser_html(resp)
        resp = self.session.post(url=res[0], data=res[1])
        print('三方投资结果为:', resp.text)
        log.info('执行接口结果为:{}'.format(resp.text))
        self.assertIn('OK', resp.text)
        log.info('断言成功')

